//
//  LKMyWorkerCheckViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/5/11.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKMyWorkerCheckViewController.h"
#import "LKMyWorkerCheckHeaderCell.h"
#import "LKWriteContinuInvestCell.h"
#import "LKTestpageNameTitleCell.h"
#import "LKMyOrderCheckStatuCell.h"
@interface LKMyWorkerCheckViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)LKBaseTableview *tableView;
@property(nonatomic,strong)NSArray *titlesArray;
@property(nonatomic,copy)NSString *customerName;
@property(nonatomic,copy)NSString *checkName;
@property(nonatomic,copy)NSString *newworker;
@property(nonatomic,copy)NSString *changeRemark;
@property(nonatomic,copy)NSString *status;
@end

@implementation LKMyWorkerCheckViewController

-(LKBaseTableview *)tableView{
    if (!_tableView) {
        _tableView = [LKBaseTableview setTableviewWithFrame:CGRectMake(0, 12 + NAVIGATION_BAR_HEIGHT, WIDTH, HEIGHT - (NAVIGATION_BAR_HEIGHT + 12)) style:UITableViewStyleGrouped registercellClasss:@[@"LKWriteContinuInvestCell",@"LKMyWorkerCheckHeaderCell",@"LKTestpageNameTitleCell",@"LKMyOrderCheckStatuCell"]];
        [self.view addSubview:_tableView];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self getApplyDetailInformation];

    self.tableView.estimatedRowHeight = 200;
    // Do any additional setup after loading the view.
}
-(void)setNavgationBackBtn{
    [super setNavgationBackBtn];
    self.navigationItem.title = @"审核";
    if (self.applyId) {
        return;
    }
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.titleLabel.font = [UIFont systemFontOfSize:16];
    [btn setTitle:@"确定" forState:UIControlStateNormal];
    [btn setTitleColor:blueDefault forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 5;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 1 || indexPath.section == 2 || indexPath.section == 3) {
        LKWriteContinuInvestCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKWriteContinuInvestCell"];
        cell.titleLabel.text = self.titlesArray[indexPath.section - 1];
        cell.arrowIcon.hidden = YES;
        if (indexPath.section == 1) {
            cell.contentLabel.text = self.customerName;
        }else if (indexPath.section == 2){
            cell.contentLabel.text = self.newworker;
        }else{
            cell.contentLabel.text = self.checkName;
        }
        return cell;
    }
    if (indexPath.section == 4) {
        LKTestpageNameTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKTestpageNameTitleCell"];
        cell.titleLabel.text = @"备注";
        cell.contentLabel.text = self.changeRemark;
        return cell;
    }
//    LKMyWorkerCheckHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKMyWorkerCheckHeaderCell"];
//    cell.statu = self.status;
    LKMyOrderCheckStatuCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKMyOrderCheckStatuCell"];
    cell.statusLabel.text = self.status;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 134;
    }
    return indexPath.section == 4 ? UITableViewAutomaticDimension : 43;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.0000000000001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 12;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [[UIView alloc] init];
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = cellHeaderBgColor;
    return view;
}
-(NSArray *)titlesArray{
    if (!_titlesArray) {
        _titlesArray = @[@"选择客户",@"选择新客户经理",@"审批人员"];
    }
    return _titlesArray;
}

/**
 获取申请的详细信息
 */
-(void)getApplyDetailInformation{
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:self.applyId,@"Id",self.type,@"Type", nil];
    [SVProgressHUD showWithStatus:@"加载中..."];
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:getMyApplyDetailUrl header:[LKUserInforTool header] parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        [SVProgressHUD dismiss];
        NSDictionary *detailDic = responseObject[@"result"];
        self.customerName = detailDic[@"customerName"] == nil ? @"":detailDic[@"customerName"];
        self.checkName = detailDic[@"approvalUserName"] == nil ? @"0":detailDic[@"approvalUserName"];
        self.changeRemark = detailDic[@"changeRemark"] == nil ? @"":detailDic[@"changeRemark"];
        if ([self.type isEqual:@"0"]) {
            self.status = detailDic[@"customerStatus"] == nil ? @"":[self backTitleAccordingType:[detailDic[@"customerStatus"] integerValue]];
        }else{
            self.status = detailDic[@"orderStatusTest"] == nil ? @"":detailDic[@"orderStatusTest"];
        }
        
        self.newworker = detailDic[@"afterContext"] == nil ? @"":detailDic[@"afterContext"];
        [self.tableView reloadData];
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}

/**
 根据状态返回具体的文字

 */
-(NSString *)backTitleAccordingType:(NSInteger)type{
    if (type == 1) {
        return @"已提交";
    }else if (type == 2){
        return @"客服审批通过";
    }else if (type == -2){
        return @"客服审批未通过";
    }else if (type == 3){
        return @"分总审批通过";
    }else if (type == -3){
        return @"分总审批未通过";
    }
    return @"";
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
